from selenium.webdriver.common.by import By
from selenium import webdriver
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import ActionChains,Keys
driver=webdriver.Edge()
driver.get('https://www.jiuxian.com/')
time.sleep(2)
a=driver.find_element(By.CLASS_NAME,'headerLogin')
# 鼠标事件
ActionChains(driver).click(a).perform()
driver.find_element(By.NAME,'uname').send_keys('13012558376')
driver.find_element(By.ID,'password').send_keys('123456Aa')
time.sleep(8)
driver.find_element(By.NAME,'bi_Usuallogin').click()
# 隐式等待
driver.implicitly_wait(10)
driver.find_element(By.CLASS_NAME,'bindSub').click()
time.sleep(3)
shuru=driver.find_element(By.XPATH,'//input[@id="wd" and @class="search-form"]')
shuru.send_keys('梦之蓝')
# 回车事件
shuru.send_keys(Keys.ENTER)
driver.find_element(By.XPATH,'//img[@src="https://img07.jiuxian.com/2023/0224/6d8be8c068b24cf68973fdc409914ba14.jpg"]').click()
# 切换窗口
driver.switch_to.window(driver.window_handles[-1])
# 显示等待
b=WebDriverWait(driver,20,0.5).until(EC.presence_of_element_located((By.NAME,'detail_jiarugouwuche')))
b.click()
driver.find_element(By.CLASS_NAME,'u-buy-go').click()
time.sleep(3)
# 浏览器刷新
driver.refresh()